package ai.mspbots.service.report.controller;

import ai.mspbots.service.report.entity.ReportEntity;
import ai.mspbots.service.report.message.provider.KafkaSender;
import cn.hutool.json.JSONUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/report")
public class ReportController {

    private static final Logger logger = LoggerFactory.getLogger(ReportController.class);

    @Autowired
    private KafkaSender kafkaSender;

    @GetMapping("/{id}")
    @ResponseBody
    public ReportEntity getReport(@PathVariable("id")Long id) {
        ReportEntity reportEntity = ReportEntity.of(id);
        logger.info("report id={}", id);
        kafkaSender.sendMessage(JSONUtil.toJsonStr(reportEntity));
        return reportEntity;
    }
}
